import Dep from './Dep';

class ComputedRef {
  constructor(value) {
    this._value = value; //默认值
  }

  get value() {
    return this._value;
  }

  set value(newValue) {
    this._value = newValue;
  }
}

export default function computed(callback) {
  Dep.effectCB = callback;
  const value = callback();
  const computedRef = new ComputedRef(value);

  //挂载静态属性
  // console.log(callback);
  //() => state1.a + state1.b.c
  callback.computedRef = computedRef;

  // console.log(callback.computedRef);
  //ComputedRef {_value: 3}

  Dep.effectCB = null;

  //返回响应式数据计算后的值
  return computedRef;
}
